home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-08-25 | 1.6 KB | 78 lines | [TEXT/CWIE] |
- /*********************************************************************
- Project : GUSI - Grand unified socket interface
- File : GUSINull.cp - Null Sockets
- Author : Matthias Neeracher
- Language : MPW C/C++
-
- $Log$
- *********************************************************************/
-
- #include <GUSIFile_P.h>
-
- #include <TextUtils.h>
-
- /************************ NullSocket members ************************/
-
- class NullSocket : public Socket {
- friend class NullSocketDomain;
- protected:
- NullSocket();
- public:
- virtual int read(void * buffer, int buflen);
- virtual int write(void * buffer, int buflen);
- virtual int select(Boolean * canRead, Boolean * canWrite, Boolean * exception);
- };
-
- /************************ NullSocket members ************************/
-
- NullSocket::NullSocket()
- {
- }
-
- int NullSocket::read(void *, int)
- {
- return 0;
- }
-
- int NullSocket::write(void *, int)
- {
- return 0;
- }
-
- int NullSocket::select(Boolean * canRead, Boolean * canWrite, Boolean * exception)
- {
- int goodies = 0;
-
- if (canRead) {
- *canRead = true;
- ++goodies;
- }
-
- if (canWrite) {
- *canWrite = true;
- ++goodies;
- }
-
- if (exception)
- *exception = false;
-
- return goodies;
- }
-
- /********************* NullSocketDomain members **********************/
-
- Boolean NullSocketDomain::Yours(const GUSIFileRef & ref, FileSocketDomain::Request request)
- {
- return !ref.spec && (request == willOpen || request == willStat)
- && equalstring((char *) ref.name, "dev:null", false, true);
- }
-
- Socket * NullSocketDomain::open(const GUSIFileRef & ref, int flags)
- {
- if (!singleton)
- singleton = new NullSocket();
- ++*singleton;
-
- return singleton;
- }
-